package csl.blog.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import csl.blog.common.entity.Blog;
import csl.blog.server.service.BlogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: TODO
 * @author: 隔山海
 * @date: 2021年10月08日 15:38
 */
@Slf4j
@RestController
@RequestMapping("blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public boolean add(@RequestBody Blog blog){
        blog.setBlogId((int)IdWorker.getId());
        return blogService.save(blog);
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    public List<Blog> queryByCondition(@RequestBody Blog blog){
        LambdaQueryWrapper<Blog> query = new LambdaQueryWrapper<>();
        query.eq(Blog::getBlogId,blog.getBlogId());
        return blogService.list(query);
    }

}
